<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>菜单编辑</title>
<link type="text/css" href="${pageContext.request.contextPath}/assets/css/common.css" rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/metro/easyui.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/mobile.css"
	rel="stylesheet" />
<style type="text/css">
.content-tab ul {
	padding: 0px;
	margin: 0px;
}
</style>
</head>
<body>
	<div>
		<!--导航栏-->
		<div class="line10"></div>
		<!--/导航栏-->

		<!--内容-->
		<div id="floatHead" class="content-tab-wrap">
			<div class="content-tab">
				<div class="content-tab-ul-wrap">
					<ul>
						<li><a class="title selected" href="javascript:;">菜单编辑</a></li>
					</ul>
				</div>
			</div>
		</div>

		<div class="tab-content">
			<dl>
				<dt>父级菜单</dt>
				<dd>
					<input id="parentMenu" disabled="disabled" name="PARENT_CODE" class="input normal"></input>
				</dd>
			</dl>
			<dl>
				<dt>菜单编码</dt>
				<dd>
					<input id="menuId" name="CODE" disabled="disabled" class="input normal"></input> <span
						class="Validform_checktip">系统自动生成，不可修改</span>
				</dd>
			</dl>
			<dl>
				<dt>菜单名称</dt>
				<dd>
					<input id="menuName" name="NAME" class="input normal"></input> <span
						class="Validform_checktip">*必填</span>
				</dd>
			</dl>
			<dl>
				<dt>菜单路径</dt>
				<dd>
					<input id="menuPath" name="MENU_PATH" class="input normal"></input>
					<span class="Validform_checktip">*必填</span>
				</dd>
			</dl>
			<dl>
				<dt>排序</dt>
				<dd>
					<input id="txtSortId" name="MENU_SORT" class="input small"></input>
					<span class="Validform_checktip">*数字，越小越向前</span>
				</dd>
			</dl>
			<dl>
				<dt>备注说明</dt>
				<dd>
					<textarea id="txtRemark" name="MEMO" class="input"></textarea>
					<span class="Validform_checktip">非必填，可为空</span>
				</dd>
			</dl>
		</div>
		<!--/内容-->

		<!--工具栏-->
		<div class="page-footer">
			<div class="btn-wrap">
				<button class="btn" onclick="save()">提交保存</button>
				<input name="btnReturn" type="button" value="返回上一页"
					class="btn yellow" onclick="javascript:history.back(-1);" />
			</div>
		</div>
		<!--/工具栏-->
	</div>
	<input type="hidden" id="flag" value="${flag}" />
	<input type="hidden" id="code" value="${code}" />
	<input type="hidden" id="action" value="${action}" />
	<script src="${pageContext.request.contextPath}/assets/js/jquery-1.11.2.min.js" charset="utf-8"
		type="text/javascript"></script>
	<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/assets/js/common.js"></script>
	<script	src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/jquery.easyui.min.js"
		charset="utf-8" type="text/javascript"></script>
	<script	src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"
		charset="utf-8" type="text/javascript"></script>
	<script type="text/javascript">
	    var contextPath = '<%=request.getContextPath()%>';
		var flag = $('#flag').val();
		var code = $('#code').val();
		var action=$('#action').val();
		$(document).ready(function() {
			if(action=='add'){//新增
				$('a.title').html('新增菜单');
				var parent_code='';
			 	if(flag=='1'){//一级菜单
			 		$('#parentMenu').parents('dl').css('display', 'none');
			 		parent_code='#';
			 	}else{//其他菜单
			 		parent_code=code;
			 		$('#parentMenu').val(code);
			 	}
				$.ajax({
					url : contextPath + "/bg/M105.do",
					data : {"parent_code":parent_code,"rnd":Math.random()},
					dataType : 'json',
					success : function(data, textStatus, jqXHR) {
						$('#menuId').val(data.menu_code);
					}
				});
			 	
			}else{//修改
				$('a.title').html('修改菜单');
			 	getMenuOne();
			}
		})
		
		//获取菜单信息(修改)
		function getMenuOne(){
			$.ajax({
				url : contextPath + "/bg/M103.do",
				data : {"CODE":code,"rnd":Math.random()},
				dataType : 'json',
				success : function(data, textStatus, jqXHR) {
					var record = data.record;
					if(data.status=='true'){
						$('#menuId').val(record.CODE);
						$('#parentMenu').val(record.PARENT_CODE);
						$('#menuName').val(record.NAME);
						$('#menuPath').val(record.MENU_PATH);
						$('#txtSortId').val(record.MENU_SORT);
						$('#txtRemark').val(record.MEMO);
					}
				}
			});
		}

		//提交保存
		function save() {
			var param = {};
			param.CODE = $('#menuId').val();
			if($.isNullOrEmpty($('#parentMenu').val())){
				param.PARENT_CODE='#';
			}else{
				param.PARENT_CODE = $('#parentMenu').val();
			}		
			param.NAME = $('#menuName').val();
			param.MENU_PATH = $('#menuPath').val();
			param.MENU_SORT = $('#txtSortId').val();
			param.MEMO = $('#txtRemark').val();
			param.rnd = Math.random();
			$.ajax({
				url : contextPath + "/bg/M102.do",
				data : param,
				dataType : 'json',
				success : function(data, textStatus, jqXHR) {	
					if(data.status=='true'){
						if(action=='add'){
				  			$.messager.show({title:'提示',msg:'新增菜单成功！',showType:'slide'});
						}
						else{
							$.messager.show({title:'提示',msg:'修改菜单成功！',showType:'slide'});
						}
						//location.href=contextPath+"/bg/menu.do";
					}else{
						if(action=='add'){
							$.messager.show({title:'提示',msg:'新增菜单失败！',showType:'slide'});
						}
						else{
							$.messager.show({title:'提示',msg:'修改菜单失败！',showType:'slide'});
						}
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					$.messager.show({title:'提示',msg:'失败！',showType:'slide'});
				}
			});
		}
	</script>
</body>
</html>